package com.rdtravel.web;

import javax.servlet.http.HttpSession;

import org.springframework.security.web.savedrequest.SavedRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/login")
class LoginController {
	private static final String SAVED_REQUEST = "SPRING_SECURITY_SAVED_REQUEST";
	public static final String URL_AFTER_AUTHENTICATION= "URL_AFTER_AUTHENTICATION";
	private static final String VIEW = "login";

	@RequestMapping(method = RequestMethod.GET)
	public ModelAndView login(HttpSession session) {
		ModelAndView modelAndView = new ModelAndView(VIEW);
		SavedRequest savedRequest = (SavedRequest) session
				.getAttribute(SAVED_REQUEST);
		if (savedRequest != null) {
			session.setAttribute(URL_AFTER_AUTHENTICATION, savedRequest.getRedirectUrl());
		}
		return modelAndView;
	}
}
